#pragma once

#include<BWAPI.h>
#include<BWTA.h>
#include<iostream>
#include<time.h>

#include"Visualizer.h"
#include"Macro.h"
#include"SpendTask.h"
#include"ZerglingControler.h"
#include"Controlers.h"
#include"MapInformation.h"

using namespace BWAPI;

class HW5 : public AIModule
{
public:
	HW5()
		:_started(false)
	{
		srand(time(NULL));
	}
	virtual void onStart()
	{
		Broodwar->setLocalSpeed(0);
		Broodwar->enableFlag(Flag::UserInput);
		Broodwar->enableFlag(Flag::CompleteMapInformation);
		BWTA::readMap();
		BWTA::analyze();
		_macro = new Macro::Macroer();
		SpendTask::Initialize();
		MapInformation::Initialize();
		_started = true;
	}
	virtual void onFrame()
	{
		if(!_started)
		{
			return;
		}
		_visualizer.Draw();
		_macro->OnFrame();
		Controlers::OnFrame();
	}
	virtual void onUnitMorph(Unit* unit)
	{
		//Broodwar->sendText("\x17 Morph: %s" , unit->getType().getName().c_str());
		_macro->OnUnitMorph(unit);
		if(unit->getPlayer() == Broodwar->self())
		{
			if(unit->getType() == UnitTypes::Zerg_Overlord)
			{
				Controlers::Add(new OverlordControler(unit));
			}
		}
	}
	virtual void onUnitCreate(Unit* unit)
	{
		//Broodwar->sendText("\x08 Create: %s" , unit->getType().getName().c_str());
		if(unit->getPlayer() == Broodwar->self())
		{
			if(unit->getType() == UnitTypes::Zerg_Zergling)
			{
				Controlers::Add(new ZerglingControler(unit));
			}
			/*else if(unit->getType() == UnitTypes::Zerg_Overlord)
			{
				Controlers::Add(new OverlordControler(unit));
			}*/
		}
	}
	virtual void onUnitShow(Unit* unit)
	{
		//Broodwar->sendText("\x08 Show: %s" , unit->getType().getName().c_str());
	}
private:
	bool _started;
	Visualizer _visualizer;
	Macro::Macroer* _macro;
};

